package com.googlecode.garbagecan.jmsstudy.openjms;

import java.util.*;
import javax.jms.*;
import javax.jms.Queue;
import javax.naming.*;

public class QueueSend {
	public static void main(String[] args) {
		try {
			Hashtable properties = new Hashtable();
			properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.exolab.jms.jndi.InitialContextFactory");
			properties.put(Context.PROVIDER_URL, "rmi://localhost:1099/");
			Context context = new InitialContext(properties);

			QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context.lookup("JmsQueueConnectionFactory");
			QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
			QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

			Queue queue = (Queue) context.lookup("queue1");
			QueueSender queueSender = queueSession.createSender(queue);

			for (int i = 0; i < 10; i++) {
				TextMessage message = queueSession.createTextMessage();
				message.setText("message" + i);
				queueSender.send(message);
			}
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
